<template>
	<el-container>
		<el-header>
			<div class="left-panel">
				<el-button icon="el-icon-plus" type="primary" @click="open_dialog" />
			</div>
			<div class="right-panel">
				<div class="right-panel-search">
					<el-input v-model="reqParams.key" clearable placeholder="点检单据号" />
					<el-button icon="el-icon-search" type="primary" @click="search" />
				</div>
			</div>
		</el-header>
		<el-main class="nopadding">
			<scTable ref="table" :api-obj="apiObj" :column="column" row-key="id" hideContextMenu>
				<!-- 固定列-选择列 -->
				<el-table-column label="#" type="index" width="40"></el-table-column>
				<el-table-column align="center" fixed="right" label="操作" width="120">
					<template #default="scope">
						<el-button round type="primary" size="small" @click="open_detail(scope.row)">
							设备点检
						</el-button>
					</template>
				</el-table-column>
				<template #status="{ data }">
					<el-tag v-if="data.status == 1" type="info">已创建</el-tag>
					<el-tag v-if="data.status == 2" type="success">已完成</el-tag>
				</template>
			</scTable>
		</el-main>

		<modify ref="modify" @complete="complete" />
		<detail ref="detail" @complete="checkComplete" />
	</el-container>
</template>

<script>
import modify from "./modify";
import detail from "./detail";

export default {
	components: {
		modify,
		detail,
	},
	data() {
		return {
			apiObj: this.$API.equipcheckdoc.page,
			reqParams: {
				key: "",
			},
			selection: [],
			column: [
				{ prop: "id", label: "id", width: 100, hide: true },
				{ prop: 'doc', label: '点检单据号', width: 100 },
				{ prop: 'equipCode', label: '设备编号', width: 100 },
				{ prop: 'equipName', label: '设备名称', width: 100 },
				{ prop: 'status', label: '状态', width: 100 },
				{ prop: 'checkTime', label: '点检时间', width: 100 },
				{ prop: 'createTime', label: '创建时间', width: 100 },
			],
		};
	},
	methods: {
		complete() {
			this.$refs.table.refresh();
		},
		checkComplete() {
			this.$refs.table.refresh();
		},
		search() {
			this.$refs.table.upData(this.reqParams);
		},
		async table_del(row) {
			let resp = await this.$API.equipcheckdoc.delete.delete([row.id]);
			if (resp.code == 200) {
				this.$refs.table.refresh();
				this.$message.success("删除成功");
			} else {
				this.$alert(resp.message, "提示", { type: "error" });
			}
		},
		async open_detail(row) {
			await this.$refs.detail.open(row);
		},
		open_dialog(row) {
			if (row.id) {
				this.$refs.modify.open(row);
			} else {
				this.$refs.modify.open();
			}
		},
	},
};
</script>
